<template>
    <div class="playlist" @click.self="$emit('popup')">
        <div class="box">
            <header>
                <p v-if="type === 0">
                    <i class="iconfont" @click="setType">&#xe8cc;</i>
                    单曲循环
                </p>
                <p v-if="type === 1">
                    <i class="iconfont" @click="setType">&#xe791;</i>
                    顺序播放
                </p>
                <p v-if="type === 2">
                    <i class="iconfont" @click="setType">&#xeb0d;</i>
                    随机播放
                </p>
                <i class="iconfont" @click="clearSings">&#xe806;</i>
            </header>
            <main>
                <ul v-if="sings.length">
                    <li v-for="(item, index) in sings" :key="item.mid">
                        <div @click="change(index)">
                            <i class="iconfont" :class="{active: iFlag === index}">&#xe80c;</i>
                            <span>{{ item.name }}</span>
                        </div>
                        <p>
                            <i class="iconfont" :class="{zan: item.zan}" @click="add(item)">&#xe60b;</i>
                            <i class="iconfont" @click="remove(item)">&#xe745;</i>
                        </p>
                    </li>
                </ul>
            </main>
            <footer @click="$emit('popup')">关闭</footer>
        </div>
    </div>
</template>
<script>
import { mapState, mapMutations } from 'vuex'
import { getSongsUrl } from '@/api/song.js'
export default {
    props: ['popup'],
    data(){
        return {
            iFlag: 0,
            praiseFlag: false
        }
    },
    computed: {
        ...mapState(['sings', 'audioUrl', 'audioIndex', 'type'])
    },
    methods: {
        ...mapMutations(['setindexaudio', 'getAudiourl', 'remove', 'clearSings', 'getpraise', 'setType']),
        async change(i){
            this.iFlag = i
            this.setindexaudio(i)
            let res = await getSongsUrl([this.sings[i]])
            await this.getAudiourl(res[this.sings[i].mid])
        },
        add(item){
            item.zan = !item.zan
            this.getpraise(item)            
        }
    }
}
</script>
<style lang="scss" scoped>
.playlist{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    background: rgba($color: #000000, $alpha: 0.1);
}
.box{
    height: 430px;
    width: 100%;
    height: 500px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #333333;
    position: absolute;
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;        
    header{
        height: 60px;
        display: flex;
        align-items: center;
        font-size: 12px;
        color: hsla(0,0%,100%,.5);
        padding: 0 30px 0 20px;
        justify-content: space-between;
        >i.iconfont{
            font-size: 14px;
        }
        p i.iconfont{
            color: rgba(255,205,49,.5);
            font-size: 20px;
            margin-right: 10px;
            vertical-align: middle;
        }
    }
    footer{
        height: 50px;
        line-height: 50px;
        text-align: center;
        background: #222222;
        color: hsla(0,0%,100%,.5);
    }
    main{
        flex: 1;
        overflow-y: scroll;
        li{
            display: flex;
            height: 30px;
            align-items: center;
            padding: 0 40px;
            justify-content: space-between;
            color: hsla(0,0%,100%,.3);
            font-size: 12px;
            p{
                i.iconfont{
                    color: #ffcd32;
                    margin-left: 20px;
                    &.zan{
                        color: crimson;
                    }
                }
            }
            div{
                width: 100%;
                height: 30px;
                display: flex;
                align-items: center;
                overflow: hidden;
                i{
                    margin-right: 10px;
                    color: transparent;
                    font-size: 12px;
                    &.active{
                        color: #ffcd32;
                    }
                }
                span{
                    display: inline-block;
                    width: 180px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                }
            }                              
        }
    }
}
</style>